/**
 * @file s_sample.h
 * @brief 
 * @author xuesong (wenshaoliu@foxmail.com)
 * @version 1.0
 * @date 2023-12-05
 * 
 * @copyright Copyright (c) 2023  by xuesong
 * 
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version <th>Author  <th>Description
 * <tr><td>2023-12-05     <td>1.0     <td>xuesong   <td>内容
 * </table>
 */
#ifndef __S_SAMPLE_H_
#define __S_SAMPLE_H_

#include "sdk_config.h"
#include "log.h"
#include "key.h"
#include "OSAL.h"
#include "gpio.h"
//-------------------------------------------------------------------------
#define  CS1259B        1
#define  CS1237         2
#define  USE_ADC_CHIP   CS1237
//---------------------------------------------------------------------
typedef union {
    struct
    {
        unsigned char subNegtiv		        : 1;    // 
    }Bit;
    uint8_t Byte;
}adcFilterFlag_t;
//-------------------------------------------------------------------------
typedef enum
{
    NOT_WATER,
    ADD_WATER,
    SUB_WATER,
}WATER_FLOW_TYPE;
typedef struct{
	union {
        struct
        {
            unsigned char WaterAdcAdd        : 1;    // 
            unsigned char WaterFlowIng       : 1;    // 
            unsigned char WaterFlowRest      : 1;    // 
            unsigned char StopTrage          : 1;    // 
        }Bit;
        uint8_t Byte;
    }Flag;
    uint8_t  WaterType;
    uint8_t  stopCnt;
    uint8_t  litterCnt;
    uint8_t  MidleCnt;
    uint8_t  BigCnt;
    uint32_t lastFiltAdc;
}WaterFlow_t;
extern WaterFlow_t  waterFlow; 
//-------------------------------------------------------------------------
typedef struct{
	union {
        struct
        {
            unsigned char init 		        : 1;    // 
            unsigned char CheckReg          : 1;    // 
            unsigned char AdcInterrNew      : 1;    //
            unsigned char disableSample     : 1;    //
            unsigned char BzdisableSample   : 1;    //
            unsigned char adcNew            : 1;    //
            unsigned char SampleNew         : 1;    //
            unsigned char resetFilter       : 1;    //
            unsigned char midleFilter       : 1;    // 启用中位值滤波
            unsigned char lock              : 1;    //
            unsigned char locked            : 1;    //
            unsigned char AtuoStartRest     : 1;    // 自动识别重置 滤波值
        }Bit;
        uint16_t Byte;
    }Flag;
    uint32_t Adc;                                   //read Adc value
    uint32_t FilterAdc;                             //Filter Adc
    uint32_t DisplayAdc;                            //外部使用Adc
}userAdc_t;
extern userAdc_t   userAdcStruct;
//-------------------------------------------------------------------------
void ADC_Precss(uint8_t taskid,uint16_t eventFlag);
void adc_median_filter(void);
void  F_DetctiveWaterFlow(void);
bool JudgeWaterOnRoad(void);
//-------------------------------------------------------------------------

#endif

